package com.niuke;

import org.checkerframework.checker.units.qual.A;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class Example {

    String str = new String("good");
    char[] ch = {'a', 'b', 'c'};

    static List<Integer> list1 = new ArrayList<>(Arrays.asList(1, 2, 3, 4));
    static List<Integer> list2 = new ArrayList<>(Arrays.asList(7, 2, 3, 10));

    public static void main(String[] args) {
        Example ex = new Example();
        ex.change(ex.str, ex.ch);
        System.out.print(ex.str + " and ");
        System.out.println(ex.ch);

        List<Integer> intersection = list1.stream().filter(new Predicate<Integer>() {
            @Override
            public boolean test(Integer integer) {

                return list2.contains(integer);
            }
        }).collect(Collectors.toList());
        System.out.println(Arrays.toString(intersection.toArray()));

        List<String> strList = list2.stream().map(new Function<Integer, String>() {
            @Override
            public String apply(Integer integer) {
                return "str" + integer;
            }
        }).collect(Collectors.toList());
        System.out.println(Arrays.toString(strList.toArray()));
    }

    public void change(String str, char ch[]) {
        str = "test ok";
        ch[0] = 'g';
    }

}
